﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UPMS.Core.Domain.Mapping
{
    public class DepartmentMap : BaseMap<Department>
    {
        public DepartmentMap()
        {
            this.ToTable("Upms_tbl_Department");
            this.Property(d => d.Name).HasColumnName("Name").IsRequired().HasMaxLength(64);
            this.Property(d => d.OrganizationId).HasColumnName("OrganizationId").IsOptional();           
            this.Property(d => d.ParentDepartmentId).HasColumnName("ParentDepartmentId").IsOptional();

            this.HasOptional(d => d.Orgaization).WithMany(org => org.Departments).HasForeignKey(d => d.OrganizationId);
            this.HasOptional(d => d.ParentDepartment).WithMany(d => d.SubDepartments).HasForeignKey(d => d.ParentDepartmentId);
            this.HasMany(d => d.SubDepartments).WithOptional(d => d.ParentDepartment).HasForeignKey(d => d.ParentDepartmentId);
        }
    }
}
